﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Fierce.Core.Aop;
using Fierce.Entity.Basic;
using Fierce.MvcExtend.Controllers;
using Fierce.Utility.Helper;
using Microsoft.AspNetCore.Mvc;

namespace Fierce.Mvc.Areas.Basic.Controllers
{
    [Area("Basic")]
    public class PostController : WorkController
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Page(string id)
        {
            BasicPost model;

            if (string.IsNullOrEmpty(id))
            {
                model = new BasicPost();
            }
            else { model = ServiceFactory.BasicPost.Get(id); }

            return View(model);
        }

        public string Grid(int rows, int page)
        {
            int total = 0;

            var list = ServiceFactory.BasicPost.Grid(rows, page, out total);

            return JsonHelper.Serialize(new { rows = list, total });
        }

        public string AllGrid()
        {
            return JsonHelper.Serialize(ServiceFactory.BasicPost.GetAll());
        }

        public string Save(BasicPost model)
        {
            return ServiceFactory.BasicPost.Save(model).Serialize();
        }

        public string Remove(string id)
        {
            return ServiceFactory.BasicPost.Delete(id).Serialize();
        }

        public string SetOrder(string id, string order)
        {
            return ServiceFactory.BasicPost.Order(id, order).Serialize();
        }
    }
}